package o;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build.VERSION;
import android.os.Handler;
import android.text.TextUtils;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.downloadengine.api.SplitTask;
import com.huawei.hms.framework.network.grs.GrsBaseInfo$CountryCodeSource;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Method;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;

public class bny {
    private static String ˊ = "";
    private static int ˋ = 0;
    private static String ˎ = "";

    bny() {
    }

    private static List<String> ᐝ() {
        List<String> arrayList = new ArrayList();
        try {
            Method method = Class.forName("android.os.SystemProperties").getMethod("get", new Class[]{String.class});
            int length = new String[]{"net.dns1", "net.dns2", "net.dns3", "net.dns4"}.length;
            for (int i = 0; i < length; i++) {
                String str = (String) method.invoke(null, new Object[]{r4[i]});
                if (!(dof.ˋ(str) || arrayList.contains(str))) {
                    arrayList.add(str);
                }
            }
        } catch (Throwable e) {
            bnc.ˎ.ˊ("Utils", "getDNS exception", e);
        } catch (Throwable e2) {
            bnc.ˎ.ˊ("Utils", "getDNS exception", e2);
        } catch (Throwable e22) {
            bnc.ˎ.ˊ("Utils", "getDNS exception", e22);
        } catch (Throwable e222) {
            bnc.ˎ.ˊ("Utils", "getDNS exception", e222);
        }
        return arrayList;
    }

    public static String ˏ() {
        List<String> ᐝ = ᐝ();
        StringBuilder stringBuilder = new StringBuilder();
        for (String append : ᐝ) {
            stringBuilder.append(append).append(";");
        }
        String append2 = stringBuilder.toString();
        if (append2.length() > 0) {
            return append2.substring(0, append2.length() - 1);
        }
        return HwAccountConstants.NULL;
    }

    public static String ˎ() {
        return ˊ;
    }

    public static void ˋ() {
        Context ॱ = bnl.ˏ().ॱ();
        if (ॱ == null) {
            ˊ = "NET_UNKNOWN";
        } else if (VERSION.SDK_INT < 23 || ॱ.checkSelfPermission("android.permission.ACCESS_NETWORK_STATE") == 0) {
            NetworkInfo activeNetworkInfo = ((ConnectivityManager) ॱ.getSystemService("connectivity")).getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
                ˊ = "NET_UNKNOWN";
                return;
            }
            switch (doo.ˊ(activeNetworkInfo)) {
                case 1:
                    ˊ = "NET_WIFI";
                    return;
                case 2:
                    ˊ = "NET_2G";
                    return;
                case 3:
                    ˊ = "NET_3G";
                    return;
                case 4:
                    ˊ = "NET_4G";
                    return;
                case 5:
                    ˊ = "NET_5G";
                    return;
                default:
                    ˊ = "NET_UNKNOWN";
                    return;
            }
        } else {
            ˊ = "NET_UNKNOWN";
        }
    }

    public static int ॱ() {
        return new SecureRandom().nextInt();
    }

    public static void ˊ(String str) {
        File file = new File(str);
        if (file.exists() && !file.delete()) {
            bnc.ˎ.ˏ("HiAppDownload", "delete file failed");
        }
    }

    public static void ˏ(SessionDownloadTask sessionDownloadTask) {
        synchronized (sessionDownloadTask) {
            bnc.ˎ.ˋ("HiAppDownload", ˊ(sessionDownloadTask, sessionDownloadTask.ˈ()));
            Handler ॱॱ = bnl.ˏ().ॱॱ();
            if (ॱॱ != null) {
                ॱॱ.sendMessage(ॱॱ.obtainMessage(sessionDownloadTask.ˈ(), sessionDownloadTask));
            }
        }
    }

    private static String ˊ(SessionDownloadTask sessionDownloadTask, int i) {
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("sendMessage: package = ").append(sessionDownloadTask.ˊˊ()).append(", interrupted = ").append(sessionDownloadTask.ˊᐝ()).append(", interrupted reason = ").append(sessionDownloadTask.interruptReason_).append(", status = ").append(i).append(", progress = ").append(sessionDownloadTask.ʼॱ());
        return stringBuffer.toString();
    }

    public static void ˋ(SessionDownloadTask sessionDownloadTask) {
        bnl.ˏ().ॱ(sessionDownloadTask);
        bnt.ˋ().ॱ(sessionDownloadTask);
        for (SplitTask ॱ : sessionDownloadTask.ᐝˊ()) {
            ॱ(ॱ);
        }
        ˎ(sessionDownloadTask);
    }

    private static void ॱ(SplitTask splitTask) {
        if (!TextUtils.isEmpty(splitTask.ˊˊ()) && new File(splitTask.ˊˊ()).exists()) {
            ˊ(splitTask.ˊˊ());
        }
        if (!TextUtils.isEmpty(splitTask.ॱˊ()) && new File(splitTask.ॱˊ()).exists()) {
            ˊ(splitTask.ॱˊ());
        }
    }

    private static void ˎ(SessionDownloadTask sessionDownloadTask) {
        String str = bnl.ˏ().ॱ().getFilesDir().getAbsolutePath() + File.separator + sessionDownloadTask.ʾ();
        if (!TextUtils.isEmpty(str) && new File(str).exists()) {
            ˊ(str);
        }
    }

    public static void ˊ(SessionDownloadTask sessionDownloadTask) throws bnj {
        if (ˎ(121)) {
            throw new bnj(121, "mock not enough space");
        } else if (!bnl.ˏ().ʻ().ˏ(sessionDownloadTask).ˋ()) {
            bnc.ˎ.ˊ("Utils", "download stopped as not enough space");
            throw new bnj(121, "not enough space");
        }
    }

    public static String ˎ(Throwable th) {
        Writer stringWriter = new StringWriter();
        th.printStackTrace(new PrintWriter(stringWriter));
        return stringWriter.toString();
    }

    public static boolean ˎ(int i) {
        if (ˊ() && bns.ॱ().ˎ() && i == bns.ॱ().ˋ()) {
            return true;
        }
        return false;
    }

    public static boolean ˊ() {
        try {
            if ((bnl.ˏ().ॱ().getApplicationInfo().flags & 2) != 0) {
                return true;
            }
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    public static String ʻ() {
        return ˎ;
    }

    public static void ॱॱ() {
        ˎ = bke.ॱ();
        if (TextUtils.isEmpty(ˎ)) {
            ˎ = GrsBaseInfo$CountryCodeSource.UNKNOWN;
        }
    }

    public static int ʼ() {
        return ˋ;
    }

    public static void ʽ() {
        ˋ = -1;
        Context ॱ = bnl.ˏ().ॱ();
        if (ॱ != null && doo.ॱॱ(ॱ)) {
            ˋ = doo.ˋॱ(ॱ);
        }
    }

    public static void ˎ(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                bnc.ˎ.ˊ("Utils", "Closeable exception:" + e.getMessage());
            } catch (RuntimeException e2) {
                bnc.ˎ.ˊ("Utils", "Closeable exception:" + e2.getMessage());
            }
        }
    }
}
